const fs = require('fs')
const { filterFiles, readPrefab } = require("./utils");

const testDir = 'E:/client/client_wbqj/assets/resources/gl_zh/';
// const testDir = 'C:/Users/chengguoqiang/Desktop/TestForCC/assets/';
//跳过处理的prefabs
let movePrefabs = ["scalePrefab"];

let files = filterFiles(testDir, '.prefab', true);

let num = 0;
let num_change = 0;
let total = files.length;
files.forEach(f => {
    console.log('scale pf', f);
    if (isRemove(f)) {
        return;
    }
    let pf = readPrefab(f);

    let change = false;
    pf.forEach(p => {
        // console.log('scale pf+++++++++++++', p)
        if (p.__type__ == 'cc.Node') {
            let _comps = p._components;
            _comps.forEach(c => {
                let _cmp = pf[c.__id__];
                let _type = _cmp.__type__;
                if (_type == 'cc.Sprite') {
                    change = true;
                    pf[c.__id__]._sizeMode = 0;
                }
            });
        }
    })

    num++;
    if (change) {
        num_change++;
        fs.writeFileSync(f, JSON.stringify(pf, null, 2));
    }
    console.log("num:" + num + "/" + total, "change_num:" + num_change);
})

/** 排除资源 */
function isRemove(path) {
    let bool = false;
    movePrefabs.forEach((a) => {
        if (path.includes(a)) {
            bool = true;
            return bool;
        }
    });
    return bool;
}
